<?php

use yii\db\Migration;

class m171112_024309_alter_orders_items_relaction extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }
    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->addColumn('{{%orders_items_relation}}', 'price_name', $this->smallInteger(2)->defaultValue(null)->comment('价格名称'));
            $this->addColumn('{{%orders_items_relation}}', 'lesson_price', $this->decimal(10,2)->defaultValue(0)->comment('价格'));
            $this->addColumn('{{%orders_items_relation}}', 'distribution_way', $this->smallInteger(2)->defaultValue(0)->comment('分成方式 0 固定 1 比例'));
            $this->addColumn('{{%orders_items_relation}}', 'distribution_proportion', $this->smallInteger(2)->defaultValue(0)->comment('分成金额或比例'));
            $this->addColumn('{{%orders_items_relation}}', 'subsidy_type', $this->smallInteger(2)->defaultValue(0)->comment('课时补贴方式（1，按学生 2 课程）'));
            $this->addColumn('{{%orders_items_relation}}', 'subsidy_money', $this->decimal(10,2)->defaultValue(0)->comment('补贴金额'));
            $this->addColumn('{{%orders_items_relation}}', 'is_scholarship', $this->decimal(10,2)->defaultValue(0)->comment('是否支持奖学金 1 是 2 否'));
            $this->addColumn('{{%orders_items_relation}}', 'scholarship', $this->decimal(10,2)->defaultValue(0)->comment('奖学金'));
            $this->addColumn('{{%orders_items_relation}}', 'art_lesson', $this->smallInteger(4)->defaultValue(0)->comment('艺教学课次数'));
            $this->addColumn('{{%orders_items_relation}}', 'art_lesson_price', $this->decimal(10,2)->defaultValue(0)->comment('艺教学课次价'));
            $this->addColumn('{{%orders_items_relation}}', 'is_art_scholarship', $this->smallInteger(1)->defaultValue(0)->comment('艺教学是否可用奖学金'));
            $this->addColumn('{{%orders_items_relation}}', 'art_scholarship', $this->decimal(10,2)->defaultValue(0)->comment('艺教学用奖学金'));
        }

    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->dropColumn('{{%orders_items_relation}}', 'price_name');
            $this->dropColumn('{{%orders_items_relation}}', 'lesson_price');
            $this->dropColumn('{{%orders_items_relation}}', 'distribution_proportion');
            $this->dropColumn('{{%orders_items_relation}}', 'distribution_way');
            $this->dropColumn('{{%orders_items_relation}}', 'subsidy_type');
            $this->dropColumn('{{%orders_items_relation}}', 'subsidy_money');
            $this->dropColumn('{{%orders_items_relation}}', 'is_scholarship');
            $this->dropColumn('{{%orders_items_relation}}', 'scholarship');
        }
    }
}
